--
-- Author: shunguo.chen
-- Date: 2018-10-05 17:13:57
--
-- LotteryRender

local IconRender = require("app.widget.renders.IconRender")

local ClassRef = app.mvc.createRenderClass(...)

--data = 
function ClassRef.create(node)
	local sprite = ClassRef.extend(node or cc.CSLoader:createNode(Res.LotterNode))
	if not node then
		ccui.Helper:doLayout(sprite)
	end
	sprite:init()
	return sprite
end

function ClassRef:init(data)
	self.super.init(self, data)

	display.setCascadeOpacityEnabled(self, true)

	self._render = IconRender.create(self._ui["Panel/Panel_icon/icon"])
	self._render:setTipEnable(true)
	self._render:setTipUnShowOrigin(true)
	self._nameText = self._ui["Panel/Panel_icon/name"]

	self._timeline = self:getTimeline()
	self._timeline:gotoFrameAndPause(0)

	self:refresh()
end

function ClassRef:refresh()
	if self._data then
		local itemData = self._data.dropItemData
		self._render:setData(itemData)
		self._nameText:setString(itemData:getName())
	end
end

function ClassRef:playAction(cb)
	self._timeline:gotoFrameAndPlay(0, false)
	local action = cca.seq({cca.fadeIn(0.3), cca.cb(cb)})
	self:runAction(action)
end

function ClassRef:onBtnClick(cb)
	self._onBtnClick = cb
end

return ClassRef